<template>
  <div>
    <el-card class="cardBox">
      <div class="title">
        <h1 class="">消防</h1>
<!--        <el-button @click="alarmBtn">报警总数：0</el-button>-->
      </div>

      <!-- 参数表格 -->
      <div style="border: 1px solid var(--el-border-color-light)">
        <el-row class="header-row">
          <el-col :span="8"></el-col>
          <el-col :span="8" class="title-col"
            ><span>消防水泵房</span></el-col
          >
          <el-col :span="8" class="status-col">
            <div class="status-container">
              <div>
                <span>通讯故障</span>
                <i class="yuan yellow"></i>
              </div>
              <div>
                <span>无故障</span>
                <i class="yuan grey"></i>
              </div>
              <div>
                <span>运行</span>
                <i class="yuan green"></i>
              </div>
              <div>
                <span>报警</span>
                <i class="yuan red"></i>
              </div>
            </div>
          </el-col>
        </el-row>
        <el-row class="threeTitle">
          <el-col :span="24">消防水池</el-col>
        </el-row>
        <el-row class="threeTitle">
          <el-col :span="6">设备</el-col>
          <el-col :span="3">液位</el-col>
          <el-col :span="3">阀门状态</el-col>
          <el-col :span="3">SS</el-col>
          <el-col :span="3"></el-col>
          <el-col :span="3"></el-col>
          <el-col :span="3"></el-col>
        </el-row>
        <el-row>
          <el-col :span="6"><el-row  ><el-col  >消防水池Ⅰ</el-col></el-row>
            <el-row ><el-col >消防水池Ⅱ</el-col></el-row></el-col>
          <el-col :span="3"><el-row  ><el-col  >{{
              NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
            }}</el-col></el-row>
            <el-row  ><el-col  >{{
                NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
              }}</el-col></el-row></el-col>
          <el-col :span="3"><el-row><el-col><div
              class="indicator-light"
              :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
          ></div></el-col></el-row>
            <el-row><el-col><div
                class="indicator-light"
                :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
            ></div></el-col></el-row>
          </el-col>

          <el-col :span="3" style="align-content: center">{{
              NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
            }}</el-col>
          <el-col :span="3" ></el-col>
          <el-col :span="3"></el-col>
          <el-col :span="3"></el-col>
        </el-row>
        <el-row class="threeTitle">
          <el-col :span="6"></el-col>
          <el-col :span="3" style="align-content: center">生活用水磁翻板液位</el-col>
          <el-col :span="6"><el-row><el-col>生活水泵状态</el-col></el-row>
            <el-row>
              <el-col :span="12">1号</el-col>
              <el-col :span="12">2号</el-col>
            </el-row></el-col>
          <el-col :span="3" style="align-content: center">生活出口管网压力值（Mpa）</el-col>
          <el-col :span="3"></el-col>
          <el-col :span="3"></el-col>
        </el-row>
        <el-row >
          <el-col :span="6">生活用水箱</el-col>
          <el-col :span="3">{{
              NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
            }}</el-col>
          <el-col :span="3"><div
              class="indicator-light"
              :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
          ></div></el-col>
          <el-col :span="3"><div
              class="indicator-light"
              :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
          ></div></el-col>
          <el-col :span="3">{{
              NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
            }}</el-col>
          <el-col :span="3"></el-col>
          <el-col :span="3"></el-col>
        </el-row>
        <el-row class="threeTitle">
          <el-col :span="6"></el-col>
          <el-col :span="9"><el-row><el-col>消防恒压水泵状态</el-col></el-row>
            <el-row>
              <el-col :span="8">1号</el-col>
              <el-col :span="8">2号</el-col>
              <el-col :span="8">3号</el-col>
            </el-row></el-col>
          <el-col :span="3" style="align-content: center">生活出口管网压力值（Mpa）</el-col>
          <el-col :span="3"></el-col>
          <el-col :span="3"></el-col>
        </el-row>
        <el-row >
          <el-col :span="6">消防水泵恒压设备</el-col>
          <el-col :span="3"><div
              class="indicator-light"
              :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
          ></div></el-col>
          <el-col :span="3"><div
              class="indicator-light"
              :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
          ></div></el-col>
          <el-col :span="3"><div
              class="indicator-light"
              :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
          ></div></el-col>
          <el-col :span="3">{{
              NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
            }}</el-col>
          <el-col :span="3"></el-col>
          <el-col :span="3"></el-col>
        </el-row>
        <el-row class="threeTitle">
          <el-col :span="6"></el-col>
          <el-col :span="6"><el-row><el-col>消防恒压水泵状态</el-col></el-row>
            <el-row>
              <el-col :span="12">1#</el-col>
              <el-col :span="12">2#</el-col>
            </el-row></el-col>
          <el-col :span="3" style="align-content: center">井下出水泵压力（Mpa）</el-col>
          <el-col :span="3" style="align-content: center">回水流量（m³/h）</el-col>
          <el-col :span="3"></el-col>
          <el-col :span="3"></el-col>
        </el-row>
        <el-row >
          <el-col :span="6">消防水泵恒压设备</el-col>
          <el-col :span="3"><div
              class="indicator-light"
              :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
          ></div></el-col>
          <el-col :span="3"><div
              class="indicator-light"
              :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
          ></div></el-col>
          <el-col :span="3">{{
              NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
            }}</el-col>
          <el-col :span="3">{{
              NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
            }}</el-col>
          <el-col :span="3"></el-col>
          <el-col :span="3"></el-col>
        </el-row>
        <el-row class="threeTitle">
          <el-col :span="6"></el-col>
          <el-col :span="3">设备编号</el-col>
          <el-col :span="3">井下消防撒水泵状态</el-col>
          <el-col :span="3">PV（Hz）</el-col>
          <el-col :span="3">SV（Hz）</el-col>
          <el-col :span="3">总管压力（Mpa）</el-col>
          <el-col :span="3">总管流量（m³/h）</el-col>
        </el-row>
        <el-row >
          <el-col :span="6" style="align-content: center">井下消防撒水泵</el-col>
          <el-col :span="3">
            <el-row><el-col>1#</el-col></el-row>
            <el-row><el-col>2#</el-col></el-row>
            <el-row><el-col>3#</el-col></el-row>
            <el-row><el-col>4#</el-col></el-row>
          </el-col>
          <el-col :span="3">
            <el-row><el-col><div
                class="indicator-light"
                :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
            ></div></el-col></el-row>
            <el-row><el-col><div
                class="indicator-light"
                :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
            ></div></el-col></el-row>
            <el-row><el-col><div
                class="indicator-light"
                :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
            ></div></el-col></el-row>
            <el-row><el-col><div
                class="indicator-light"
                :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
            ></div></el-col></el-row>
          </el-col>
          <el-col :span="3">
            <el-row><el-col>{{
                NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
              }}</el-col></el-row>
            <el-row><el-col>{{
                NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
              }}</el-col></el-row>
            <el-row><el-col>{{
                NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
              }}</el-col></el-row>
            <el-row><el-col>{{
                NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
              }}</el-col></el-row>
          </el-col>
          <el-col :span="3">
            <el-row><el-col>{{
                NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
              }}</el-col></el-row>
            <el-row><el-col>{{
                NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
              }}</el-col></el-row>
            <el-row><el-col>{{
                NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
              }}</el-col></el-row>
            <el-row><el-col>{{
                NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
              }}</el-col></el-row>
          </el-col>
          <el-col :span="3" style="align-content: center">{{
              NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
            }}</el-col>
          <el-col :span="3" style="align-content: center">{{
              NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
            }}</el-col>
        </el-row>
        <el-row class="threeTitle"><el-col :span="24">药箱</el-col></el-row>
        <el-row >
          <el-col :span="6">1-药箱</el-col>
          <el-col :span="2">1-1液位</el-col>
          <el-col :span="1">{{
              NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
            }}</el-col>
          <el-col :span="2">1-2液位</el-col>
          <el-col :span="1">{{
              NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
            }}</el-col>
          <el-col :span="2">1-1搅拌机</el-col>
          <el-col :span="1"><div
              class="indicator-light"
              :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
          ></div></el-col>
          <el-col :span="2">1-1加药泵</el-col>
          <el-col :span="1"><div
              class="indicator-light"
              :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
          ></div></el-col>
          <el-col :span="2">1-2搅拌机</el-col>
          <el-col :span="1"><div
              class="indicator-light"
              :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
          ></div></el-col>
          <el-col :span="2">1-2加药泵</el-col>
          <el-col :span="1"><div
              class="indicator-light"
              :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
          ></div></el-col>
        </el-row>
        <el-row >
          <el-col :span="6">2-药箱</el-col>
          <el-col :span="2">2-1液位</el-col>
          <el-col :span="1">{{
              NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
            }}</el-col>
          <el-col :span="2">2-2液位</el-col>
          <el-col :span="1">{{
              NamePD_42_N("Mot1OutputCurr_AI", operator.NO, null, 2)
            }}</el-col>
          <el-col :span="2">2-1搅拌机</el-col>
          <el-col :span="1"><div
              class="indicator-light"
              :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
          ></div></el-col>
          <el-col :span="2">2-1加药泵</el-col>
          <el-col :span="1"><div
              class="indicator-light"
              :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
          ></div></el-col>
          <el-col :span="2">2-2搅拌机</el-col>
          <el-col :span="1"><div
              class="indicator-light"
              :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
          ></div></el-col>
          <el-col :span="2">2-2加药泵</el-col>
          <el-col :span="1"><div
              class="indicator-light"
              :class="
                NamePD_42_N('Inv1RunFeed_DI', operator.NO).value
                  ? 'green'
                  : 'grey'
              "
          ></div></el-col>
        </el-row>
      </div>
    </el-card>

    <!-- 公司log -->
    <el-row>
      <div class="kx-log-box">
        <img
          class="kx-img"
          src="@/assets/images/kxauto.png"
          alt="描述图片的文字"
        />
        <span>开轩自动化</span>

        <span class="kx-hezuo">
          商务合作：18509234888（同微信） 技术支持：18691805301（同微信）
        </span>
      </div>
    </el-row>

    <!-- 弹窗 -->
    <form-dialog ref="formRef" />
    <sensorFormDialog ref="sensorRef" />
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted, computed } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
// 引入子组件
import formDialog from "./alarmForm.vue";
import sensorFormDialog from "./sensorForm.vue";
import { act, createWebSocket } from "@/utils/websocket"; //引入websocket
import { operator } from "@/utils/op_enums";
import { NamePD_42_N, NamePD_42_N_GEN } from "@/utils/beltPositioningMethod.ts";
const HUANINGBH = [
  "HNLineLock1_DI",
  "HNLineLock2_DI",
  "HNLineLock3_DI",
  "HNLineLock4_DI",
  "HNLineLock5_DI",
  "HNLineLock6_DI",
  "HNLineLock7_DI",
  "HNLineLock8_DI",
  "HNLineLock9_DI",
  "HNLineLock10_DI",
  "HNLineLock11_DI",
  "HNLineLock12_DI",
  "HNLineLock13_DI",
  "HNLineLock14_DI",
  "HNLineLock15_DI",
  "HNLineLock16_DI",
  "HNLineLock17_DI",
  "HNLineLock18_DI",
  "HNLineLock19_DI",
  "HNLineLock20_DI",
  "HNLineLock21_DI",
  "HNLineLock22_DI",
  "HNLineLock23_DI",
  "HNLineLock24_DI",
  "HNLineLock25_DI",
  "HNLineLock26_DI",
  "HNLineLock27_DI",
  "HNLineLock28_DI",
  "HNLineLock29_DI",
  "HNLineLock30_DI",
  "HNLineLock31_DI",
  "HNLineLock32_DI",
  "HNLineLock33_DI",
  "HNLineLock34_DI",
  "HNLineLock35_DI",
  "HNLineLock36_DI",
  "HNLineLock37_DI",
  "HNLineLock38_DI",
  "HNLineLock39_DI",
  "HNLineLock40_DI",
  "HNLineLock41_DI",
  "HNLineLock42_DI",
  "HNLineLock43_DI",
  "HNLineLock44_DI",
  "HNLineLock45_DI",
  "HNLineLock46_DI",
  "HNLineLock47_DI",
  "HNLineLock48_DI",
];
// const NamePD_42_N = (
//   key: string,
//   op: operator,
//   op_number?: number,
//   retain?: number
// ) =>
//   computed(() => {
//     return useTagResults(act.PD_42_N.PD_42_N[key], op, op_number, retain);
//   });
// const NamePD_42_N_GEN = (
//   key: string,
//   op: operator,
//   op_number?: number,
//   retain?: number
// ) =>
//   computed(() => {
//     return useTagResults(act.PD_42_N.PD_42_N_GEN[key], op, op_number, retain);
//   });
onMounted(() => {
  createWebSocket("%PD_42_2%");
});
const formRef = ref();
const sensorRef = ref();
const alarmBtn = () => {
  formRef.value.openDialog();
};
const sensorBtn = () => {
  sensorRef.value.openDialog();
};
const faultResetBtn = () => {
  ElMessage.info("故障复位");
};
</script>

<style lang="scss" scoped>
.cardBox {
  background-color: var(--el-bg-color);
  border-radius: 8px;
  box-shadow: var(--el-box-shadow-light);
  border: 1px solid var(--el-border-color-light);

  /* 左上方标题 */
  .title {
    border-bottom: 1px solid var(--el-border-color);
    padding-bottom: 15px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;

    h1 {
      color: var(--el-text-color-primary);
      font-size: 20px;
      margin: 0;
      font-weight: 500;
    }

    .el-button {
      background-color: var(--el-color-danger);
      color: var(--el-color-white);
      border: none;
      border-radius: 4px;
      padding: 8px 15px;
      font-weight: 500;

      &:hover {
        background-color: var(--el-color-danger-light-3);
      }
    }
  }

  /* 表格标题 + 四个指示灯 */
  .header-row {
    display: flex;
    align-items: center;
    background-color: var(--el-fill-color-lighter);
    font-weight: 500;
    color: var(--el-text-color-primary);
    padding: 10px;
    .el-col {
      height: 40px;
      display: flex;
      align-items: center;
      border: 1px solid transparent;
    }

    .title-col {
      justify-content: center;

      span {
        font-size: 18px;
      }
    }

    .status-col {
      justify-content: end;
      .status-container {
        display: flex;
        gap: 14px;

        div {
          background: var(--el-fill-color-blank);
          border: 1px solid var(--el-border-color-lighter);
          border-radius: 4px;
          padding: 4px 8px;
          display: flex;
          align-items: center;
          gap: 6px;
          font-size: 13px;

          span {
            padding: 0 4px;
          }

          .yuan {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            flex-shrink: 0;
            @extend %status-colors;
          }
        }
      }
    }
  }

  /* 表格的标题 项目 + 状态值 */
  .threeTitle {
    .el-col {
      background-color: var(--el-fill-color) !important;
    }
  }

  /* 每一小格子的边框 背景色 */
  .el-col {
    border: 1px solid var(--el-border-color-lighter);
    text-align: center;
    padding: 6px 5px;
    font-size: 13px;
    color: var(--el-text-color-regular);

    &:first-child,
    &:nth-child(5),
    &:nth-child(7),
    &:nth-child(9) {
      font-weight: 500;
      // color: blue;
      color: var(--el-text-color-primary);
      background-color: var(--el-fill-color-lighter);
    }
  }

  /* 子页面设备参数--指示灯 */
  .indicator-light {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: var(--el-border-color);
    margin: 0 auto;
    @extend %status-colors;
  }

  /* 华宁沿线闭锁 */
  .huaning-title {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--el-text-color-primary);
    font-weight: 500;
  }

  .hn-container {
    display: flex;
    flex-wrap: wrap;
    gap: 50px;
    padding: 8px;
    align-items: center;
    background-color: var(--el-fill-color-lighter);
    border-radius: 4px;

    span {
      display: flex;
      align-items: center;
      gap: 6px;
    }

    .hn-span {
      display: inline-flex;
      align-items: center;
    }
  }

  .index-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
    justify-content: flex-start;
    background-color: var(--el-fill-color-lighter);
    border-radius: 4px;
    min-height: 40px;
    align-items: center;
  }

  .index-circle {
    width: 26px;
    height: 26px;
    background-color: var(--el-border-color);
    border-radius: 50%;
    color: var(--el-text-color-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 12px;
    font-weight: 500;
    @extend %status-colors;
  }

  // 定义基础颜色类（只定义一次）
  %status-colors {
    &.green {
      background-color: var(--el-color-success);
    }
    &.red {
      background-color: var(--el-color-danger);
    }
    &.yellow {
      background-color: var(--el-color-warning);
    }
    &.grey {
      background-color: var(--el-border-color-dark); // 比默认边框色更深的灰色
    }
  }
}
.el-col-AAAA{
  padding: 0px 0px !important;
  border: 1px solid var(--el-border-color-lighter);
  text-align: center;
  font-size: 13px;
}
</style>
